package com.momin.gmall.product.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.momin.common.utils.PageUtils;
import com.momin.common.utils.Query;

import com.momin.gmall.product.dao.AttrGroupDao;
import com.momin.gmall.product.entity.AttrGroupEntity;
import com.momin.gmall.product.service.AttrGroupService;


@Service("attrGroupService")
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEntity> implements AttrGroupService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrGroupEntity> page = null;
        Long catId = Long.parseLong(params.get("catId").toString());
        QueryWrapper<AttrGroupEntity> attrGroupEntityQueryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(String.valueOf(params.get("key")))){
            attrGroupEntityQueryWrapper.and((obj) -> {
                obj.eq("attr_group_id", params.get("key"))
                        .or().like("attr_group_name", params.get("key"));
            });
        }
        if(catId==0){

            page = this.page(new Query<AttrGroupEntity>().getPage(params),
                    attrGroupEntityQueryWrapper);
        }else{
            attrGroupEntityQueryWrapper.eq("catelog_id",params.get("catId"));
            page = this.page(
                    new Query<AttrGroupEntity>().getPage(params),attrGroupEntityQueryWrapper);
        }
        return new PageUtils(page);
    }

}